package com.tg.service.config;

import com.tg.service.protoType.PrototypeEntity;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

@Configuration
public class ScriptEngineConfig {
    /**
     * 注入ScriptEngine
     *
     * @return ScriptEngine
     */
    @Bean
    @Scope("prototype")
    public ScriptEngine loadScriptEngine() {
        return new ScriptEngineManager().getEngineByName("nashorn");
    }

    @Bean
    @Scope("prototype")
    public PrototypeEntity loadPrototypeEntity() {
        PrototypeEntity entity = new PrototypeEntity();
        entity.setAmount(1);
        return entity;
    }
}
